<?php
class CategoryAction extends Action{
	
	public function _initialize() //初始化操作
	{
		$config = D('setting')->getConfig();
		$categoryItem = getCategoryCache();
		$this->assign('categoryItem',$categoryItem);
		$this->assign('site_config',$config);
		A('Public')->right();//载入右侧信息
	}
	
	public function index()
	{
		$id = intval($_GET['id']);
		if(empty($id))
			$this->error('参数错误!');
		$posts = D('posts');
		$count = $posts->where(array('cid'=>$id))->count();
		if ($count>'0')
		{
			import("ORG.Util.Page");
			$Page = new Page($count,10);
			$show = $Page->show();
			$articleList = $posts->where(array('cid'=>$id))->field('id,subject,description,createdate,click_count')->limit($Page->firstRow.','.$Page->listRows)->order('id desc')->select();
			$categoryName = self::getCategoryName($id);
			$this->assign('articleList',$articleList);
			$this->assign('categoryName',$categoryName);
			$this->assign('page',$show);
			
			
		}
		else
		{
			$this->assign('errorMsg','此栏目暂时没有文章!!');
			
		}
		$this->display();
			
		
		
		
	}
	
	protected static function getCategoryName($id)
	{
		return M('category')->where(array('id'=>$id))->find();
	}
	
}
?>